package org.kgc.alanhealth.service.impl;
import org.kgc.alanhealth.entity.HospitalAntidiabetics;
import org.kgc.alanhealth.entity.HospitalArticle;
import org.kgc.alanhealth.entity.HospitalEncyclopedia;
import org.kgc.alanhealth.mapper.HospitalAntidiabeticsMapper;
import org.kgc.alanhealth.mapper.HospitalArticleMapper;
import org.kgc.alanhealth.mapper.HospitalEncyclopediaMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
@Service
public class BaikeServiceImpl {
    @Autowired
    private HospitalArticleMapper hospitalArticleMapper;
    @Autowired
    private HospitalEncyclopediaMapper hospitalEncyclopediaMapper;
    @Autowired
private HospitalAntidiabeticsMapper hospitalAntidiabeticsMapper;
    //获取热门文章
    public List<HospitalArticle> getHotArticles(Integer currentPageNo,Integer pageSize){

        return hospitalArticleMapper.getHotArticles((currentPageNo-1)*pageSize,pageSize);
    }
//获取全部的健康百科记录
    public List<HospitalEncyclopedia> getAllRecords() {
        return hospitalEncyclopediaMapper.selectAll();
    }
    //根据一级健康百科记录查找对应的二级记录
    public List<HospitalAntidiabetics> findAntidiabeticsByEncyName(String encyName) {
        // 查询百科记录
        HospitalEncyclopedia encyclopedia = hospitalEncyclopediaMapper.findByEncyName(encyName);
        if (encyclopedia == null) {
            // 如果百科记录不存在，返回空列表
            return Collections.emptyList();
        }

        // 查询二级列表
        return hospitalAntidiabeticsMapper.findByEncyclopediaId(encyclopedia.getId());
    }
    //根据二级记录，查找相应的文章
    public List<HospitalArticle> findArticlesByEncyName(String encyName) {
        //查询二级记录
        HospitalAntidiabetics antidiabetics =hospitalAntidiabeticsMapper.findByEncyName(encyName);
        if (antidiabetics == null) {
            return Collections.emptyList();
        }
        return hospitalArticleMapper.findByAntiId(antidiabetics.getId());
    }
    //根据文章标题显示文章内容
    public List<HospitalArticle> findArticlesByAntiTitle(String antiTitle) {
        return hospitalArticleMapper.findByAntiTle(antiTitle);
    }

    public int getAllByArticlesCount() {
        return hospitalArticleMapper.getAllByArticlesCount();
    }
}
